/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Principal;


import Assembler.lexa;
import Assembler.parsera;
import Data.Tipo;
import Interprete.Nodo;
import Interprete.NodoAritmetico;
import Interprete.NodoCondicion;
import Interprete.NodoGlobal;
import Interprete.NodoLLamada;
import Interprete.NodoMetodo;
import Interprete.NodoMov;
import Interprete.NodoSalto;
import Traductor.parsero;
import com.nilo.plaf.nimrod.NimRODLookAndFeel;
import com.nilo.plaf.nimrod.NimRODTheme;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import Optimizacion.*;
import Traductor.lext;
import Traductor.parsert;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Stack;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author REI
 */
public class Traductor extends javax.swing.JFrame {

    /**
     * Creates new form Principal
     */
    EditorTexto tab;
    String salida;
    File archivoaux;
    File archivonivel;
    File archivoenemigo;
    File archivojugador;
    Optimizador optimiza;
    EditorAssembler editorasm;
    String archivoasm;
    
    ///traductor
    private HashMap Tabla;
    private int[] pila, heap;
    public ArrayList<Nodo> instrucciones;
    private ArrayList<NodoGlobal> globales;
    private Stack pila_llamadas;
    private Stack pila_op;
    private int step=0;
    public int normal = 0;
    
    public Traductor() {
        
        setDefaultLookAndFeelDecorated(true);
        setBackground(Color.WHITE);
        try {

            NimRODTheme tema = new NimRODTheme("src/Temas/NimRODThemeFile1.theme");
            NimRODLookAndFeel milook = new NimRODLookAndFeel();

            NimRODLookAndFeel.setCurrentTheme(tema);
            UIManager.setLookAndFeel(milook);



        }catch (Exception e) {
            System.out.println(e);
        }
        initComponents();
        optimiza = new Optimizador();
        editorasm = new EditorAssembler();
        editorasm.jTextArea1.setEditable(false);
        paneldebug.add(editorasm);
        archivoasm ="";

    }
    
    public void AbrirArchivos()
    {
        boolean cargado = false;
        String[] patharchivo = null;
        JFileChooser choosercargar = new JFileChooser();
        choosercargar.setFileFilter(new Filtro("ejecutable", "archivo *.ejecutable"));



        choosercargar.showOpenDialog(this);


        if (choosercargar.getSelectedFile() != null) {
            salida = choosercargar.getSelectedFile().getAbsolutePath();
            File f = new File(salida);
            if (!f.exists()) {


                JOptionPane.showMessageDialog(null, "No Selecciono un Archivo");    //No existe
                } else {
                cargado = true;
                patharchivo = new String[2];
                patharchivo[0]=f.getName();
                patharchivo[1]=salida;
            }
        }// final del if

        if (cargado == true) {

            try {


                if (patharchivo != null && estaAbierto(patharchivo) ) {
                File archivo = null;
                BufferedReader entrada = null;
                String lectura = "";
                String contenido = "";
                archivo = new File(patharchivo[1].trim());
                contenido = "";
                if (archivo.getName().toLowerCase().endsWith(".ejecutable")) {
                    try {
                        entrada = new BufferedReader(new FileReader(archivo));
                    } catch (FileNotFoundException ex) {
                        System.out.println("no se puede leer el archivo");
                    }
                    try {
                        lectura = entrada.readLine();
                        while (lectura != null) {
                            contenido = contenido + lectura + "\n";
                            lectura = entrada.readLine();
                        }
                    } catch (IOException ex) {
                        System.out.println("fallo el buffer de lectura");
                    }


                      tab  = new EditorTexto();
                      tab.Inicializar(patharchivo[0],patharchivo[1], contenido);
                      tab.Analizar();
                      Tabbs.add(patharchivo[0], tab);
                      Tabbs.setSelectedIndex(Tabbs.getTabCount()-1);


                }

            }




            }catch (Exception ex) {
                ex.printStackTrace();

        }


        } else {

            
        }
    }
    
    public boolean estaAbierto(String[] path) {

        EditorTexto temp;
        String paths = "";
        for (int i = 0; i < Tabbs.getTabCount(); i++) {
            temp = (EditorTexto ) Tabbs.getComponentAt(i);
            paths = temp.getPath();
            if (paths.compareTo(path[1]) == 0) {
                Tabbs.setSelectedIndex(i);
                return false;
            }
        }
        return true;
    }
    
    public void GuardarArchivo(String path, String contenido) {
        File archivo = null;
        BufferedWriter escribir = null;

        try {
            archivo = new File(path);
            escribir = new BufferedWriter(new FileWriter(archivo));

            if (contenido != null) {
                escribir.write(contenido);

                }
            escribir.close();
        } catch (IOException ex) {
        }
    }
    
    public void Guardar()
    {
        if(Tabbs.getComponentCount()!=0)
         {
        EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());

         if(aux!=null)
         {
            GuardarArchivo(aux.getPath(), aux.getContenido());
         }
         }
    }
    
    public void Copiar()
    {
         if(Tabbs.getComponentCount()!=0)
         {
        EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());

         if(aux!=null)
         {
            aux.copiar();
         }
         
         }
    }
    
    public void Pegar()
    {
        if(Tabbs.getComponentCount()!=0)
         {
        EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());

         if(aux!=null)
         {
            aux.pegar();
         }
         }
    }
    
    public void GuardarComo()
    {
        if(Tabbs.getComponentCount()!=0)
         {
        String miarchivo;
        String ext;
        JFileChooser choosercargar = new JFileChooser();
        choosercargar.setFileFilter(new Filtro("ejecutable", "archivo *.ejecutable"));
        

        choosercargar.showSaveDialog(this);
        
        if (choosercargar.getSelectedFile() != null) {
            miarchivo = choosercargar.getSelectedFile().getAbsolutePath();

            ext = choosercargar.getFileFilter().getDescription();
            ext = ext.substring(ext.length()-11, ext.length());
            
            
            if(Tabbs.getComponentCount()!=0)
            {
                 EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());
                 if(aux!=null)
                 {
                    GuardarArchivo(miarchivo+ext, aux.getContenido());
                 }
            }
            
             
            
            
        }
        else
        {
             JOptionPane.showMessageDialog(null, "No Selecciono un Archivo");    //No existe
        }
        
        }
            
    }
    
    public File Abrir(String extension)
    {
        File archivo = null;
        String path;
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new Filtro(extension,"archivo *."+extension));
        chooser.showOpenDialog(this);
        
        if(chooser.getSelectedFile()!=null)
        {
            path = chooser.getSelectedFile().getAbsolutePath();
            archivo = new File(path);
            if(archivo.exists())
            {
                return archivo;
            }
            else
            {
                return archivo;
            }
        }
        
        return archivo;
    }
    
    public void Optimizar()
    {   if(Tabbs.getComponentCount()!=0)
         {
        boolean optimizacion = false;
        boolean generacionasm = false;
        EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());
        parsero miparser;
        parsert traductorasm;
        File f;
        String nombreasm="";
        String codigoasm ="";
         if(aux!=null)
         {
            f = new File(aux.getPath());
            try {
                optimiza.IniciarOptimizacion(f);
                optimizacion = true;
                
            }catch (Exception ex) {
                optimizacion = false;
                JOptionPane.showMessageDialog(this,"Se produjo un error en la optimizacion\n por favor verifique el codigo");
                Logger.getLogger(Traductor.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            
            if(optimizacion)
            {
                JOptionPane.showMessageDialog(this,"Optimizacion correcta!!!");
                try {
                    traductorasm = new parsert(new lext(new FileInputStream(f)));
                    traductorasm.parse();
                    nombreasm = f.getAbsolutePath().replace(".ejecutable",".asm");
                    archivoasm = nombreasm;
                    codigoasm = traductorasm.salida;
                    GuardarArchivo(nombreasm,codigoasm );
                    generacionasm = true;
                } catch (Exception ex) {
                    generacionasm = false;
                    JOptionPane.showMessageDialog(this,"Se produjo un error en la traduccion a ASM\n por favor verifique el codigo");
                    Logger.getLogger(Traductor.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                if(generacionasm)
                {
                    editorasm.jTextArea1.setText(codigoasm);
                    editorasm.Analizar();
                }
            }
            
            
         }
         
         }
        
    }

    public void Analizar()
    {
        if(Tabbs.getComponentCount()!=0)
         {
        
        EditorTexto aux = (EditorTexto)Tabbs.getComponentAt(Tabbs.getSelectedIndex());
        analizador miparser;
        File f;
        Guardar();
         if(aux!=null)
         {
            f = new File(aux.getPath());
            try {
                miparser = new analizador(new FileInputStream(f));
                miparser.iniciar();


            } catch (FileNotFoundException ex) {
                Logger.getLogger(Traductor.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(Traductor.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
         
         }

    }
    
    public String ObtenerPath(String dire)
    {
        String direccion="";
        String diraux;        
        diraux = dire.replace("\\", "//");
        String dir[];
        dir = diraux.split("//");
             
        for(int i=0; i < dir.length -1; i++)
        {
            direccion = direccion + dir[i] + "\\";
        }
        
        return direccion;
    }

    public void cargarCodigoAsm()
    {
        File f = new File(archivoasm);
        boolean cargado = false;
        if(f.exists())
        {
            parsera parserasm = null;
            try {
                parserasm = new parsera(new lexa(new FileInputStream(f)));
                parserasm.parse();
                cargado = true;
                
            } catch (Exception ex) {
                cargado = false;
                Logger.getLogger(Traductor.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            if(cargado)
            {
                inicializarTraductor(parserasm);
                ejecutar(false);
            }
            
        }
        
    }
    
    private void inicializarTraductor(parsera parser)
    {
        Tabla = parser.getTabla();
        instrucciones = parser.getInstrucciones();
        globales = parser.getGlobales();
        pila_llamadas = new Stack();
        pila_op = new Stack();
        pila = new int[10000];
        heap = new int[10000];
        Tabla.put("pila", pila);
        Tabla.put("heap", heap);
        Tabla.put("pila_op", pila_op);
        actualizarPila();
        actualizarHeap();
        actualizarGlobales();
        actualizarPilaOp();
    }
    
    public void actualizarPila()
    {
        String [] titulos= {"Pos.","Valor"};
        DefaultTableModel dtm = new DefaultTableModel(null,titulos);
        Object data[] = new Object[2];
        for(int i = 0; i < pila.length; i++)
        {
            data[0]= i;
            data[1]= pila[i];
            dtm.addRow(data);
        }
        
        tablapila.setModel(dtm);
    }
    
    public void actualizarHeap()
    {
        String [] titulos= {"Pos.","Valor"};
        DefaultTableModel dtm = new DefaultTableModel(null,titulos);
        Object data[] = new Object[2];
        for(int i = 0; i < heap.length; i++)
        {
            data[0]= i;
            data[1]= heap[i];
            dtm.addRow(data);
        }
        
        tablaheap.setModel(dtm);
    }
    
    public void actualizarGlobales()
    {
        String [] titulos= {"Pos.","Valor"};
        DefaultTableModel dtm = new DefaultTableModel(null,titulos);
        Object data[] = new Object[2];
        for(NodoGlobal global : globales)
        {
            data[0]= global.getVar();
            data[1]= global.getVal();
            dtm.addRow(data);
        }
        
        tablasimbolos.setModel(dtm);
    }
    
    public void actualizarPilaOp()
    {
         Enumeration numero = pila_op.elements();
         String [] titulos= {"Pos.","Valor"};
         DefaultTableModel dtm = new DefaultTableModel(null,titulos);
         Object data[] = new Object[2];
         int i =0;
         Object obj;
         while(numero.hasMoreElements())
         {
             obj = numero.nextElement();
             data[0]= String.valueOf(i);
             data[1]= obj;
             dtm.addRow(data);
         }
         
         tablaoperaciones.setModel(dtm);
    }
    
    public void ejecutar(boolean eject) {
        int resultado;
        boolean ejecutar = eject;
        boolean esMain=false;
        int i;
        try {
            for (i = 0; i < instrucciones.size(); i++) {
                if (ejecutar) {
                     
//                    resultado = instrucciones.get(i).calcular(Tabla);
                    switch (instrucciones.get(i).getTipo()) {
                        case Tipo.CONDICION:
                            
                             System.out.println("en condicion");
                              int ope = operacionCondicion(instrucciones.get(i));                              
                              i = ope == 1 ? i : i+1;
                            
                            break;

                        case Tipo.SALTO:
                              System.out.println("en salto");
                              int res = operacionSalto(instrucciones.get(i));
                              i = res - 1;
//                            i = resultado - 1;
                            break;
                        case Tipo.LLAMADA:
                              
                              resultado = operacionLlamada(instrucciones.get(i));
                            if (resultado != -1) {
                                guardarLlamada(i);
                                i = resultado - 1;
                            }
                            break;
                        case Tipo.SALIDA:
                            i = salirLlamada();
                            if(i==-1) {
                        i=instrucciones.size();
                    }                            
                            break;
                        case Tipo.ASIGNACION:
                            System.out.println("asi normal");
                            operacionAsignacion(instrucciones.get(i));
                            break;
                        case Tipo.VEC_ASIGNACION:
                            System.out.println("asi vec");
                            operacionAsigVectores(instrucciones.get(i));
                            break;
                        case Tipo.VEC_ACCESO:
                            System.out.println("vec acc");
                            operacionAccesoVectores(instrucciones.get(i));
                            break;
                        case Tipo.OPERADOR:
                            System.out.println("operacion");
                            operacionAritmetica(instrucciones.get(i));
                            break;
                    }
                } else {
                    if (instrucciones.get(i).getTipo() == Tipo.METODO) {
                        
                        ejecutar = operacionMetodo(instrucciones.get(i));
                        
                        if(ejecutar)
                        {
                            step = i;
                            normal = i;
                            break;
                                    
                        }
                        
                    }
                }
            }
        } catch (Exception ex) {
        }
    }
    
    
    public void ejecutarPaso()
    {
        int resultado;
        
        try {
            
                if(step < instrucciones.size())
                {
                    //                    resultado = instrucciones.get(i).calcular(Tabla);
                    switch (instrucciones.get(step).getTipo()) {
                        case Tipo.CONDICION:
                            
                             System.out.println("en condicion");
                              int ope = operacionCondicion(instrucciones.get(step));                              
                              step = ope == 1 ? step : step+1;
                            
                            break;

                        case Tipo.SALTO:
                              System.out.println("en salto");
                              int res = operacionSalto(instrucciones.get(step));
                              step = res - 1;
//                            i = resultado - 1;
                            break;
                        case Tipo.LLAMADA:
                              
                              resultado = operacionLlamada(instrucciones.get(step));
                            if (resultado != -1) {
                                guardarLlamada(step);
                                step = resultado - 1;
                            }
                            break;
                        case Tipo.SALIDA:
                            step = salirLlamada();
                            if(step==-1) {
                        step=instrucciones.size();
                    }                            
                            break;
                        case Tipo.ASIGNACION:
                            System.out.println("asi normal");
                            operacionAsignacion(instrucciones.get(step));
                            break;
                        case Tipo.VEC_ASIGNACION:
                            System.out.println("asi vec");
                            operacionAsigVectores(instrucciones.get(step));
                            break;
                        case Tipo.VEC_ACCESO:
                            System.out.println("vec acc");
                            operacionAccesoVectores(instrucciones.get(step));
                            break;
                        case Tipo.OPERADOR:
                            System.out.println("operacion");
                            operacionAritmetica(instrucciones.get(step));
                            break;
                    }
                
                    
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "Termino la ejecucion paso a paso");
                }
                     

            
        } catch (Exception ex) {
        }
    }
    
    public void ejecutarNormal()
    {
        int resultado;
        
        try {
            
                
                    //                    resultado = instrucciones.get(i).calcular(Tabla);
                    switch (instrucciones.get(normal).getTipo()) {
                        case Tipo.CONDICION:
                            
                             System.out.println("en condicion");
                              int ope = operacionCondicion(instrucciones.get(normal));                              
                              normal = ope == 1 ? normal : normal+1;
                            
                            break;

                        case Tipo.SALTO:
                              System.out.println("en salto");
                              int res = operacionSalto(instrucciones.get(normal));
                              normal = res - 1;
//                            i = resultado - 1;
                            break;
                        case Tipo.LLAMADA:
                              
                              resultado = operacionLlamada(instrucciones.get(normal));
                            if (resultado != -1) {
                                guardarLlamada(normal);
                                normal = resultado - 1;
                            }
                            break;
                        case Tipo.SALIDA:
                            normal = salirLlamada();
                            if(normal==-1) {
                        normal=instrucciones.size();
                    }                            
                            break;
                        case Tipo.ASIGNACION:
                            System.out.println("asi normal");
                            operacionAsignacion(instrucciones.get(normal));
                            break;
                        case Tipo.VEC_ASIGNACION:
                            System.out.println("asi vec");
                            operacionAsigVectores(instrucciones.get(normal));
                            break;
                        case Tipo.VEC_ACCESO:
                            System.out.println("vec acc");
                            operacionAccesoVectores(instrucciones.get(normal));
                            break;
                        case Tipo.OPERADOR:
                            System.out.println("operacion");
                            operacionAritmetica(instrucciones.get(normal));
                            break;
                    }
                    
                   
                     

            
        } catch (Exception ex) {
        }
    }
    
    
    public void operacionAsigVectores(Nodo nodo)
    {
        NodoMov nuevo = (NodoMov)nodo;
        NodoGlobal izq;
        NodoGlobal vec;
        NodoGlobal ind;
        int indice = 0;
        int asignacion = 0;
        if(nuevo.getOp1().compareTo("pila")==0)
        {
                       
            try{


            indice = Integer.parseInt(nuevo.getOp2());

            }catch(NumberFormatException ex){
                ind = buscarEnTabla(nuevo.getOp2());
                if(ind!=null)
                {
                    indice = Integer.parseInt(ind.getVal());
                }
            }

            if(nuevo.getOp3().compareTo("pila_op")==0)
            {
                try{
            
                    String tope = pila_op.pop().toString();
                    asignacion = Integer.parseInt(tope);

                }catch(NullPointerException ex)
                {
                    System.out.println("error en la pila_op");
                }
                
                pila[indice] = asignacion;
                actualizarPila();
            }
            else
            {
                try{
                    
                    
                    asignacion = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            asignacion = Integer.parseInt(ind.getVal());
                        }
                    }
                
                    pila[indice] = asignacion;
                    actualizarPila();
            }
                    
                
        }
        else
        {
            try{


            indice = Integer.parseInt(nuevo.getOp2());

            }catch(NumberFormatException ex){
                ind = buscarEnTabla(nuevo.getOp2());
                if(ind!=null)
                {
                    indice = Integer.parseInt(ind.getVal());
                }
            }

            if(nuevo.getOp3().compareTo("pila_op")==0)
            {
                try{
            
                    String tope = pila_op.pop().toString();
                    asignacion = Integer.parseInt(tope);

                }catch(NullPointerException ex)
                {
                    System.out.println("error en la pila_op");
                }
                
                heap[indice] = asignacion;
                actualizarHeap();
            }
            else
            {
                try{
                    
                    
                    asignacion = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            asignacion = Integer.parseInt(ind.getVal());
                        }
                    }
                
                    heap[indice] = asignacion;
                    actualizarHeap();
            }
        }
        
    }
    
    public void operacionAccesoVectores(Nodo nodo)
    {
        NodoMov nuevo = (NodoMov)nodo;
        NodoGlobal izq;
        NodoGlobal vec;
        NodoGlobal ind;
        int indice = 0;
        if(nuevo.getOp1().compareTo("pila_op")==0)
        {
            if(nuevo.getOp2().compareTo("pila")==0)
                {
                    try{
                    
                    
                    indice = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            indice = Integer.parseInt(ind.getVal());
                        }
                    }
                    
                    pila_op.push(String.valueOf(pila[indice]));                    
                    actualizarPilaOp();
                    
                }
                else
                {
                    try{
                    
                    
                    indice = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            indice = Integer.parseInt(ind.getVal());
                        }
                    }
                    
                    pila_op.push(String.valueOf(heap[indice]));                    
                    actualizarPilaOp();
                }
        }
        else
        {
            izq = buscarEnTabla(nuevo.getOp1());
            if(izq!=null)
            {
                if(nuevo.getOp2().compareTo("pila")==0)
                {
                    try{
                    
                    
                    indice = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            indice = Integer.parseInt(ind.getVal());
                        }
                    }
                    
                    izq.setVal(String.valueOf(pila[indice]));
                    Tabla.put(izq.getVar(),izq.getVal());
                    actualizarPila();
                    actualizarGlobales();
                    
                }
                else
                {
                    try{
                    
                    
                    indice = Integer.parseInt(nuevo.getOp3());
                    
                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp3());
                        if(ind!=null)
                        {
                            indice = Integer.parseInt(ind.getVal());
                        }
                    }
                    
                    izq.setVal(String.valueOf(heap[indice]));
                    Tabla.put(izq.getVar(),izq.getVal());
                    actualizarHeap();
                    actualizarGlobales();
                }
            }
        }
        
        
        
        
    }
    
    public void operacionAsignacion(Nodo nodo)
    {
        NodoMov nuevo = (NodoMov)nodo;
        NodoGlobal izq;
        NodoGlobal vec;
        NodoGlobal ind;
        int indice = 0;
        if(nuevo.getOp1().compareTo("pila_op")==0)
        {
            
            try{


            indice = Integer.parseInt(nuevo.getOp2());

            }catch(NumberFormatException ex){
                ind = buscarEnTabla(nuevo.getOp2());
                if(ind!=null)
                {
                    indice = Integer.parseInt(ind.getVal());
                }
            }

            pila_op.push(String.valueOf(indice));                    
            actualizarPilaOp();
                    
                
        }
        else
        {
            izq = buscarEnTabla(nuevo.getOp1());
            if(izq!=null)
            {
                
                
                if(nuevo.getOp2().compareTo("pila_op")==0)
                {
                    try{
            
                        String tope = pila_op.pop().toString();
                        indice = Integer.parseInt(tope);

                    }catch(NullPointerException ex)
                    {
                        System.out.println("error en la pila_op");
                    }
                    
                    izq.setVal(String.valueOf(indice));
                    Tabla.put(izq.getVar(),izq.getVal());
                    actualizarGlobales();
                }
                else
                {
                try{

                    indice = Integer.parseInt(nuevo.getOp2());

                    }catch(NumberFormatException ex){
                        ind = buscarEnTabla(nuevo.getOp2());
                        if(ind!=null)
                        {
                            indice = Integer.parseInt(ind.getVal());
                        }
                    }

                    izq.setVal(String.valueOf(indice));
                    Tabla.put(izq.getVar(),izq.getVal());
                    actualizarGlobales();
                    
                }
            }
        }
        
    }
    
    public void operacionAritmetica(Nodo nodo)
    {
        NodoAritmetico aritmetico = (NodoAritmetico)nodo;
        int resultado =0;
        int op1 = 0;
        int op2 = 0;
        
        try{
            
            String tope = pila_op.pop().toString();
            op1 = Integer.parseInt(tope);
            
        }catch(NullPointerException ex)
        {
            System.out.println("error en la pila_op");
        }
        
        try{
            
            String tope = pila_op.pop().toString();
            op2 = Integer.parseInt(tope);
            
        }catch(NullPointerException ex)
        {
            System.out.println("error en la pila_op");
        }
        
        switch(aritmetico.getOp())
        {
            case '+':
                resultado = op1 + op2;
                pila_op.push(resultado);
                break;
            case '-':
                resultado = op1 - op2;
                pila_op.push(resultado);
                break; 
             case '*':
                resultado = op1 * op2;
                pila_op.push(resultado);
                break;
             case '/':
                resultado = op1 / op2;
                pila_op.push(resultado);
                break;
             case '%':
                resultado = op1 + op2;
                pila_op.push(resultado);
                break;
        }
        
        actualizarPilaOp();
                
    }
    
    
    public int operacionCondicion(Nodo nodo)
    {
        int resultado = 0;
        NodoCondicion condicion = (NodoCondicion)nodo; 
        NodoGlobal izq;
        NodoGlobal der;
        int valizq = 0;
        int valder = 0;
        boolean valor;
        
        try
        {
            valizq = Integer.parseInt(condicion.getOp1());
            
        }catch(NumberFormatException ex)
        {
            izq = buscarEnTabla(condicion.getOp1());
            
            if(izq!=null)
            {
                valizq = Integer.parseInt(izq.getVal());
            }
        }
        
        try
        {
            valder = Integer.parseInt(condicion.getOp2());
            
        }catch(NumberFormatException ex)
        {
            der = buscarEnTabla(condicion.getOp2());
            
            if(der!=null)
            {
                valder = Integer.parseInt(der.getVal());
            }
        }
        
        if(EvaluarCondicion(valizq, valder, condicion.getOp()))
        {
            return 1;
        }
        else
        {
            return 0;
        }
        
        
        
    }
    
    private boolean EvaluarCondicion(int operando2, int operando1, char operador){
        
        boolean retorno = false;
        
        switch (operador) {
            case '<':
                return operando2 < operando1;
            case '>':
                return operando2 > operando1;
            case '?':
                return operando2 <= operando1;
            case '!':
                return operando2 >= operando1;
            case '=':
                return operando2 == operando1;
            case '#':
                return operando2 != operando1;
        }
        
        return retorno;
        
    }
    
    public int operacionSalto(Nodo nodo)
    {
        NodoSalto salto = (NodoSalto)nodo;
        int linea =0;
        
        String etiqueta = salto.getEtiqueta();
        try
        {
            linea = Integer.parseInt(Tabla.get(etiqueta).toString());
        }catch(NumberFormatException ex)
        {
            System.out.println("error en la etiqueta buscada"+ linea);
        }
        
        
        return linea;
    }
    
    public int operacionLlamada(Nodo nodo)
    {
        NodoLLamada salto = (NodoLLamada)nodo;
        int linea =-1;
        
        String metodo = salto.getMetodo();
        
        if(metodo.compareTo("Print_val")!=0)
        {
            try
            {
                linea = Integer.parseInt(Tabla.get(metodo).toString());
                return linea;
            }catch(NumberFormatException ex)
            {
                System.out.println("error en el metodo buscado"+ linea);
            }
        }
        else
        {
            //codigo para print
        }
        
        
        
        return linea;
    }
    
    public boolean operacionMetodo(Nodo nodo)
    {
        
        NodoMetodo metodo = (NodoMetodo)nodo;
        String nombremetodo = metodo.getMetodo();
        if(nombremetodo.toUpperCase().contains("MAIN"))
        {
            return true;
        }
        else
        {
            return false;
        }
        
    }
    public NodoGlobal buscarEnTabla(String nombre)
    {
        NodoGlobal encontrado = null;
        
        for(NodoGlobal global: globales)
        {
            if(global.getVar().compareTo(nombre)==0)
            {
                return global;
            }
        }
        return encontrado;
    }
    
    private void guardarLlamada(int pos) {
        pila_llamadas.push(pos);

    }

    private int salirLlamada() {
        try {
            return Integer.parseInt(pila_llamadas.pop().toString());
        } catch (Exception ex) {
            return -1;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        btabrir = new javax.swing.JButton();
        btguardar = new javax.swing.JButton();
        btguardarcomo = new javax.swing.JButton();
        btcopiar = new javax.swing.JButton();
        btpegar = new javax.swing.JButton();
        btcompilar = new javax.swing.JButton();
        Tabbs = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jToolBar2 = new javax.swing.JToolBar();
        bthabilitar = new javax.swing.JButton();
        btiniciar = new javax.swing.JButton();
        btpasos = new javax.swing.JButton();
        btnormal = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablapila = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaheap = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablasimbolos = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        tablaoperaciones = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        paneldebug = new javax.swing.JTabbedPane();

        jToolBar1.setRollover(true);

        btabrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/open.png"))); // NOI18N
        btabrir.setToolTipText("Abrir");
        btabrir.setFocusable(false);
        btabrir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btabrir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btabrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btabrirActionPerformed(evt);
            }
        });
        jToolBar1.add(btabrir);

        btguardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/save.png"))); // NOI18N
        btguardar.setToolTipText("guardar");
        btguardar.setFocusable(false);
        btguardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btguardarActionPerformed(evt);
            }
        });
        jToolBar1.add(btguardar);

        btguardarcomo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/filesaveas.png"))); // NOI18N
        btguardarcomo.setToolTipText("Guardar Como..");
        btguardarcomo.setFocusable(false);
        btguardarcomo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btguardarcomo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btguardarcomo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btguardarcomoActionPerformed(evt);
            }
        });
        jToolBar1.add(btguardarcomo);

        btcopiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/copy.png"))); // NOI18N
        btcopiar.setToolTipText("Copiar");
        btcopiar.setFocusable(false);
        btcopiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btcopiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btcopiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btcopiarActionPerformed(evt);
            }
        });
        jToolBar1.add(btcopiar);

        btpegar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/paste.png"))); // NOI18N
        btpegar.setToolTipText("Pegar");
        btpegar.setFocusable(false);
        btpegar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btpegar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btpegar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btpegarActionPerformed(evt);
            }
        });
        jToolBar1.add(btpegar);

        btcompilar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/optimization.png"))); // NOI18N
        btcompilar.setToolTipText("optimizar");
        btcompilar.setFocusable(false);
        btcompilar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btcompilar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btcompilar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btcompilarActionPerformed(evt);
            }
        });
        jToolBar1.add(btcompilar);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 1009, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Tabbs, javax.swing.GroupLayout.DEFAULT_SIZE, 1009, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Tabbs, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Editor Codigo 3D", jPanel2);

        jToolBar2.setRollover(true);

        bthabilitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/enabled.png"))); // NOI18N
        bthabilitar.setToolTipText("Habilitar");
        bthabilitar.setFocusable(false);
        bthabilitar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bthabilitar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar2.add(bthabilitar);

        btiniciar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/run.png"))); // NOI18N
        btiniciar.setToolTipText("normal");
        btiniciar.setFocusable(false);
        btiniciar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btiniciar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btiniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btiniciarActionPerformed(evt);
            }
        });
        jToolBar2.add(btiniciar);

        btpasos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/step.png"))); // NOI18N
        btpasos.setToolTipText("paso a paso");
        btpasos.setFocusable(false);
        btpasos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btpasos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btpasos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btpasosActionPerformed(evt);
            }
        });
        jToolBar2.add(btpasos);

        btnormal.setText("normal");
        btnormal.setFocusable(false);
        btnormal.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnormal.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnormal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnormalActionPerformed(evt);
            }
        });
        jToolBar2.add(btnormal);

        tablapila.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Posicion", "Valor"
            }
        ));
        jScrollPane2.setViewportView(tablapila);

        tablaheap.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Posicion", "Valor"
            }
        ));
        jScrollPane3.setViewportView(tablaheap);

        tablasimbolos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Variable", "Valor"
            }
        ));
        jScrollPane4.setViewportView(tablasimbolos);

        tablaoperaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Posicion", "Valor"
            }
        ));
        jScrollPane5.setViewportView(tablaoperaciones);

        jLabel1.setText("PILA");

        jLabel2.setText("HEAP");

        jLabel3.setText("TABLA SIMBOLOS");

        jLabel4.setText("PILA OP");

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane6.setViewportView(jTextArea2);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                            .addComponent(paneldebug))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 217, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(94, 94, 94)
                                        .addComponent(jLabel2))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel4)))
                                .addGap(31, 31, 31)))
                        .addGap(98, 98, 98))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(paneldebug, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Ejecucion", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btpegarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btpegarActionPerformed
        // TODO add your handling code here:
        Pegar();
}//GEN-LAST:event_btpegarActionPerformed

    private void btcopiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btcopiarActionPerformed
        // TODO add your handling code here:
        Copiar();
}//GEN-LAST:event_btcopiarActionPerformed

    private void btguardarcomoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btguardarcomoActionPerformed
        // TODO add your handling code here:
        GuardarComo();
}//GEN-LAST:event_btguardarcomoActionPerformed

    private void btguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btguardarActionPerformed
        // TODO add your handling code here:
        Guardar();
}//GEN-LAST:event_btguardarActionPerformed

    private void btabrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btabrirActionPerformed
        // TODO add your handling code here:
        AbrirArchivos();
}//GEN-LAST:event_btabrirActionPerformed

    private void btcompilarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btcompilarActionPerformed
        // TODO add your handling code here:
        Guardar();
        Optimizar();
    }//GEN-LAST:event_btcompilarActionPerformed

    private void btiniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btiniciarActionPerformed
        // TODO add your handling code here:
        cargarCodigoAsm();
    }//GEN-LAST:event_btiniciarActionPerformed

    private void btpasosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btpasosActionPerformed
        // TODO add your handling code here:
        ejecutarPaso();
        step++;
        System.out.println("instruccion: "+step);
    }//GEN-LAST:event_btpasosActionPerformed

    private void btnormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnormalActionPerformed
        // TODO add your handling code here:
        Ejecucion eje = new Ejecucion(this);
        eje.Iniciar();
    }//GEN-LAST:event_btnormalActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Traductor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Traductor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Traductor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Traductor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Traductor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane Tabbs;
    private javax.swing.JButton btabrir;
    private javax.swing.JButton btcompilar;
    private javax.swing.JButton btcopiar;
    private javax.swing.JButton btguardar;
    private javax.swing.JButton btguardarcomo;
    private javax.swing.JButton bthabilitar;
    private javax.swing.JButton btiniciar;
    private javax.swing.JButton btnormal;
    private javax.swing.JButton btpasos;
    private javax.swing.JButton btpegar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JTabbedPane paneldebug;
    private javax.swing.JTable tablaheap;
    private javax.swing.JTable tablaoperaciones;
    private javax.swing.JTable tablapila;
    private javax.swing.JTable tablasimbolos;
    // End of variables declaration//GEN-END:variables
}
